<?php
    include './init.php';

    $name = $_POST['name'];
    $password = md5($_POST['password']);


    $sql = "select id,name from user where name='$name' and password='$password'";

    $result = mysql_query($sql);

    if($result && mysql_affected_rows()>0){
        echo '登录成功';
        //将用户信息写入SESSION
        $_SESSION['admin'] = mysql_fetch_assoc($result);

        echo '<meta http-equiv="refresh" content="2;url=index.php" />';
    }else{
        echo '登录失败';
        echo '<meta http-equiv="refresh" content="2;url='.$_SERVER['HTTP_REFERER'].'" />';
    }
    
